/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.32                          *
*        Compiled Oct  8 2015, 11:59:02                              *
*        (c) 2015 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
#include "stdio.h"
#include "stdbool.h"
#include "stdlib.h"
#include "main.h"
// USER END

#include "DIALOG.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_WINDOW_0    (GUI_ID_USER + 0x00)
#define ID_TEXT_0    (GUI_ID_USER + 0x03)
#define ID_BUTTON_0    (GUI_ID_USER + 0x05)


// USER START (Optionally insert additional defines)
#define ID(i)  GUI_ID_USER + 0x05+i
char buf[10];
//static unsigned char data[32]; 
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
void addLabel(void);
void showdata(void);

extern bool isPush;
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { WINDOW_CreateIndirect, "AllData", ID_WINDOW_0, 0, 0, 854, 480, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "Text", ID_TEXT_0, 0, 0, 854, 50, 0, 0x64, 0 },
  { BUTTON_CreateIndirect, "BACK", ID_BUTTON_0, 340, 410, 150, 50, 0, 0x0, 0 },
  // USER START (Optionally insert additional widgets)
  // USER END
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

// USER START (Optionally insert additional static code)

extern WM_HWIN CreateMainWin(void);
extern WM_HWIN Createsetting(void);
extern WM_HWIN Createstart(void);
extern WM_HWIN CreateAllData(void);

extern bool isShowData;
// USER END

/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int     NCode;
  int     Id;
  // USER START (Optionally insert additional variables)

  
  // USER END

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    //
    // Initialization of 'AllData'
    //
    hItem = pMsg->hWin;
    WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00C0C0C0));
    //
    // Initialization of 'Text'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
    TEXT_SetText(hItem, "All Datas");
    TEXT_SetFont(hItem, GUI_FONT_32B_ASCII);
    TEXT_SetTextColor(hItem,GUI_DARKBLUE);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
    //
    // Initialization of 'BACK'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    BUTTON_SetFont(hItem, GUI_FONT_32_ASCII);
    BUTTON_SetText(hItem, "BACK");
    BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_DARKBLUE);
    //BUTTON_SetTextColor(hItem,BUTTON_CI_PRESSED,GUI_RED);
    // USER START (Optionally insert additional code for further widget initialization)

    // USER END
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_BUTTON_0: // Notifications sent by 'BACK'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        
            WM_HideWindow(hWinAllData);
            //WM_ShowWindow(hWinMain);
         
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    // USER START (Optionally insert additional code for further Ids)
    // USER END
    }
    break;
  // USER START (Optionally insert additional message handling)
  // USER END
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateAllData
*/
WM_HWIN CreateAllData(void);
WM_HWIN CreateAllData(void) {
  WM_HWIN hWin;

  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}

// USER START (Optionally insert additional public code)
void addLabel()
{
    int i=0,j=0;
    int x=40,y=100;
    int ch=0;
    TEXT_Handle hObj;
    for(i=0;i<4;i++)
    {
        for(j=0;j<8;j++)
        {
            sprintf(buf,"CH%2d:",ch);
            hObj = TEXT_CreateEx(x, y,50, 20,hWinAllData, WM_CF_SHOW,TEXT_CF_LEFT, GUI_ID_USER + 0x04,buf);
            TEXT_SetFont(hObj, GUI_FONT_24B_ASCII);
            TEXT_SetTextColor(hObj,GUI_DARKBLUE);

            hObj = TEXT_CreateEx(x+60, y,50, 20,hWinAllData, WM_CF_SHOW,TEXT_CF_LEFT, ID(ch++),"0");
            TEXT_SetFont(hObj, GUI_FONT_24B_ASCII);
            TEXT_SetTextColor(hObj,GUI_CYAN);

            x+=100;
        }
        x=40;
        y+=80;
    }
      
}
unsigned char RxBuf[32];
void showdata()
{
    WM_HWIN hItem;
    int i=0;
    for(i=0;i<32;i++)
    {
        //data[i] = RxBuf[i];
        hItem = WM_GetDialogItem(hWinAllData, ID(i));
        sprintf(buf, "%3d", RxBuf[i]);
        TEXT_SetText(hItem, buf);
    }
}

// USER END

/*************************** End of file ****************************/
